package com.example.springboot.config.config;

import com.example.springboot.config.intercepter.TestIntercepter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 注册bean
 */
@Configuration
public class InterceptorConfig extends WebMvcConfigurerAdapter {

    //	@Autowired
//	private InterceptorConfMapper mapper;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration interceptorRegistration = registry.addInterceptor(getTestIntercepter());
//		InterceptorRegistration exRegistration = registry.addInterceptor(new InterceptorConf());
        // 多个拦截器组成一个拦截器链
        // addPathPatterns 用于添加拦截规则
        // excludePathPatterns 用户排除拦截
        interceptorRegistration.addPathPatterns("/**");
//		List<InterceptorConfPo> list = mapper.getInterceptorList();
//		//遍历数据库中配置的地址拦截信息
//		for (InterceptorConfPo info : list) {
//			interceptorRegistration.excludePathPatterns(info.getConfUrl());
//			exRegistration.addPathPatterns(info.getConfUrl());
//		}
        super.addInterceptors(registry);
    }

    @Bean
    public TestIntercepter getTestIntercepter() {
        return new TestIntercepter();
    }
}